package com.woniu.cq.mallcommon.common;

import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import io.jsonwebtoken.security.Keys;

import java.security.Key;
import java.util.Date;
import java.util.Map;

/**
 * @author Daniel
 * @version 1.0.0
 * @ClassName JwtUntil
 * @Description TODO
 * @createTime 2020年09月24日 14:22:00
 */
public class JwtUntil {

    public static String sert = "adasdsadasdadasdadsadasdasdsadaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";

    /**
     * @description: 创建Token
     * @param: maps
     * @param: sec
     * @return: java.lang.String
     */
    public static String createToken(Map<String, Object> maps,Integer sec){
        Key key = Keys.hmacShaKeyFor(sert.getBytes());
        return Jwts.builder()
                .setClaims(maps)
                .setExpiration(new Date(System.currentTimeMillis()+sec*1000))
                .signWith(key)
                .compact();
    }
    /**
     * @description: 获得Token
     * @param: jwt
     * @return: java.lang.String
     */
    public static Map<String, Object> parseToken(String jwt){
        Key key = Keys.hmacShaKeyFor(sert.getBytes());
        return Jwts.parserBuilder().setSigningKey(key).build().parseClaimsJws(jwt).getBody();
    }
}
